﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.WebControls;
using NetDon.eBoss.Data.CollectionClasses;
using NetDon.eBoss.Data.EntityClasses;
using NetDon.eBoss.Data.HelperClasses;
using NetDon.eBoss.Portal;
using NetDon.eBoss.Portal.HtmlTool;
using NetDon.Utilities;
namespace NetDon.OA.Portal.HtmlTool
{
    public partial class HtmlTemplateManagement : NetDonPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                Bind();
               
            }
        }


        void Bind()
        {
            var collection =  new TemplateCollection();
            collection.GetMulti(null);
            this.gridCustomerInfoList.DataSource = collection;
            this.gridCustomerInfoList.DataBind();
        }
    
        protected void btnReload_Click(object sender, EventArgs e)
        {
            Bind();
        }


        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Bind();
        }

        protected void btnDeleteDemand_Click(object sender, EventArgs e)
        {
            
            var customerId = fieldCustomerId.Value.ToInt32();
            if(customerId.HasValue)
            {
                var collection = new HtmltoolaccounttemplateCollection();
                collection.GetMulti(HtmltoolaccounttemplateFields.Content == customerId);
                var htmlToolAccount = collection.FirstOrDefault();
                if (htmlToolAccount!=null)
                {

                    Alert(string.Format("不可以删除。该Html模版被账号-{0}下的HtmlTool分类-{1}使用",
                          new HtmltoolaccountEntity(htmlToolAccount.Accountid.Value).Accountname,
                          new HtmltoolcategoryruleEntity (htmlToolAccount.Categoryruleid.Value).Category));
                    return;
                }
                 bool result = new TemplateEntity(customerId.Value).Delete();

            if (result)
            {
                Bind();
                Alert("删除成功!");
            }
            else
            {
                Alert("删除失败！");
            }
            }
           
        }



    }
}